﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.Logging;




namespace ERP.Manager.BusinessServices
{
    public class LoginServices
    {

        private readonly ContextService contextService;
        private readonly UserinfoServices userService;
        private ILog LOGGER = LogManager.GetCurrentClassLogger();


        public LoginServices(ContextService contextService, UserinfoServices userService)
        {
            this.contextService = contextService;
            this.userService = userService;
        }



        public virtual bool InitializeUserDataInSession(string name)
        {
            try
            {
                var user = userService.getUserByName(name);
                contextService.Id = user.id;
                contextService.UserId =user.userId;
                contextService.UserName = user.userName;
                contextService.DepartmentId = user.DepartmentInfo.departmentId;
                return true;
            }
            catch (Exception e)
            {
                LOGGER.Debug(e.Message);
            }

            return false;
        }

    }
}
